import React from 'react'
import {Row,Col,InputNumber,Input,Button,Icon} from 'antd'
import styles from "./index.less";
import { METHODS } from 'http';

class CodeCongfig extends React.Component{
	constructor(props){
		super(props)
		this.state = {
            codeStart:"",
            codeEnd:"",
		}
	}
    showMenu(i){
		const { changeMenu } = this.props
		changeMenu(i)
    }
    click = () =>{
        const { codeList,newCode,updateCode } = this.props
        const params = {
            codeStart:this.state.codeStart || codeList[0].codeStart,
            codeEnd:this.state.codeEnd || codeList[0].codeEnd,
        }
        if(codeList != ""){
            params.id = codeList[0].id
            updateCode(params)
        }else{
            newCode(params)
        }
        
    } 
    firstChange = (value) => {
        this.setState({codeStart:value})
    }
    endChange = (value) => {
        this.setState({codeEnd:value})
    }
	render(){
        const {codeList} = this.props
        if(!codeList){
            return null
        }
		return(
            <div>
                <Button type="primary" onClick={this.showMenu.bind(this,1)}>
		        		<Icon type="left" />返回
		      	</Button>
                <h5 style={{lineHeight:"40px",fontWeight:600}}>请输入条形码号段</h5>
                <div>
                    <InputNumber defaultValue={codeList != ""?codeList[0].codeStart:""} onChange={this.firstChange}/>
                    <span> - </span>    
                    <InputNumber defaultValue={codeList != ""?codeList[0].codeEnd:""} onChange={this.endChange}/>
                </div>
                <Button type="primary" style={{marginTop:10,width:100}} onClick={this.click}>
		        	保存
		      	</Button>
            </div>
		)
	}
}
export default CodeCongfig